﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ColorSquare
{
    public partial class MainForm : Form
    {

        private Color[] colors = new Color[] { Color.Red, Color.Blue, Color.Yellow};
        private int index = 0;

        public MainForm()
        {
            InitializeComponent();
   
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            InitView();
        }

        private void InitView() {
            this.MinimumSize = new Size((int)(color_square.Width*1.2), (int)(color_square.Height*1.2));
            color_square.Click += new EventHandler(ColorSquareClick);
        }

        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);

            int x = (int)(0.5 * (this.Width - color_square.Width));
            int y = (int)(0.5 * (this.Height - color_square.Height));
            color_square.Location = new System.Drawing.Point(x, y);
            int tipx = (int)(0.5 * (this.Width - lab_tip.Width));
            int tipy = (int)(y - lab_tip.Height * 1.2);
            lab_tip.Location = new Point(tipx, tipy);
            
        }

        private void ColorSquareClick(object sender, EventArgs e) {
            index = (index + 1) % colors.Length;
            color_square.BackColor = colors[index];
        }
    }
}
